home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / MELL / NETLIB00 / !NetLib / sys / h / socket < prev    next >
Encoding:
Text File  |  1997-01-24  |  9.8 KB  |  277 lines

  1. /*
  2.  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)socket.h    8.4 (Berkeley) 2/21/94
  34.  */
  35.  
  36. #ifndef __sys_socket_h
  37. #define __sys_socket_h
  38.  
  39. /* Freenet programmers interface - sys/socket.h - edit by andy 23/5/95 */
  40.  
  41. #include "Internet:sys.h.types"
  42.  
  43. /*
  44.  * Definitions related to sockets: types, address families, options.
  45.  */
  46.  
  47. /*
  48.  * Socket types
  49.  */
  50. #define SOCK_STREAM     1         /* Stream socket */
  51. #define SOCK_DGRAM    2         /* Datagram socket */
  52. #define SOCK_RAW    3         /* Raw socket */
  53. #define    SOCK_RDM    4      /* reliably-delivered message */
  54. #define    SOCK_SEQPACKET    5      /* sequenced packet stream */
  55.  
  56. /*
  57.  * Address families
  58.  */
  59. #define    AF_UNSPEC       0        /* unspecified */
  60. #define    AF_LOCAL    1        /* local to host (pipes, portals) */
  61. #define    AF_UNIX        AF_LOCAL    /* backward compatibility */
  62. #define AF_INET     2         /* Internet */
  63. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  64. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  65. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  66. #define    AF_NS        6        /* XEROX NS protocols */
  67. #define    AF_ISO        7        /* ISO protocols */
  68. #define    AF_OSI        AF_ISO
  69. #define    AF_ECMA        8        /* european computer manufacturers */
  70. #define    AF_DATAKIT    9        /* datakit protocols */
  71. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  72. #define    AF_SNA        11        /* IBM SNA */
  73. #define AF_DECnet    12        /* DECnet */
  74. #define AF_DLI        13        /* DEC Direct data link interface */
  75. #define AF_LAT        14        /* LAT */
  76. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  77. #define    AF_APPLETALK    16        /* Apple Talk */
  78. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  79. #define    AF_LINK        18        /* Link layer interface */
  80. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  81. #define    AF_COIP        20        /* connection-oriented IP, aka ST II */
  82. #define    AF_CNT        21        /* Computer Network Technology */
  83. #define pseudo_AF_RTIP    22        /* Help Identify RTIP packets */
  84. #define    AF_IPX        23        /* Novell Internet Protocol */
  85. #define    AF_SIP        24        /* Simple Internet Protocol */
  86. #define pseudo_AF_PIP    25        /* Help Identify PIP packets */
  87.  
  88. /*
  89.  * We need to know the IPv6 address family number even on IPv4-only systems.
  90.  * Note that this is NOT a protocol constant, and that if the system has its
  91.  * own AF_INET6, different from ours below, all of BIND's libraries and
  92.  * executables will need to be recompiled after the system <sys/socket.h>
  93.  * has had this type added.  The type number below is correct on most BSD-
  94.  * derived systems for which AF_INET6 is defined.
  95.  */
  96. #ifndef AF_INET6
  97. /* SNB: NOTE: This clashes with AF_SIP above.  I've never heard of SIP, and
  98.  * I trust Paul Vixie, so I'm going to leave it in here as 24
  99.  */
  100. #define AF_INET6    24
  101. #endif
  102.  
  103. #define    AF_MAX        26
  104.  
  105. /*
  106.  * Protocol families
  107.  */
  108. #define    PF_UNSPEC    AF_UNSPEC
  109. #define    PF_LOCAL    AF_LOCAL
  110. #define    PF_UNIX        PF_LOCAL    /* backward compatibility */
  111. #define PF_INET     AF_INET   /* Internet */
  112. #define    PF_IMPLINK    AF_IMPLINK
  113. #define    PF_PUP        AF_PUP
  114. #define    PF_CHAOS    AF_CHAOS
  115. #define    PF_NS        AF_NS
  116. #define    PF_ISO        AF_ISO
  117. #define    PF_OSI        AF_ISO
  118. #define    PF_ECMA        AF_ECMA
  119. #define    PF_DATAKIT    AF_DATAKIT
  120. #define    PF_CCITT    AF_CCITT
  121. #define    PF_SNA        AF_SNA
  122. #define PF_DECnet    AF_DECnet
  123. #define PF_DLI        AF_DLI
  124. #define PF_LAT        AF_LAT
  125. #define    PF_HYLINK    AF_HYLINK
  126. #define    PF_APPLETALK    AF_APPLETALK
  127. #define    PF_ROUTE    AF_ROUTE
  128. #define    PF_LINK        AF_LINK
  129. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  130. #define    PF_COIP        AF_COIP
  131. #define    PF_CNT        AF_CNT
  132. #define    PF_SIP        AF_SIP
  133. #define    PF_IPX        AF_IPX        /* same format as AF_NS */
  134. #define PF_RTIP        pseudo_AF_FTIP    /* same format as AF_INET */
  135. #define PF_PIP        pseudo_AF_PIP
  136. #define PF_INET6    AF_INET6    /* IPv6 */
  137. #define    PF_MAX        AF_MAX
  138.  
  139. /*
  140.  * 4.3 BSD compatibility structure representing socket addresses
  141.  */
  142. struct sockaddr {
  143.   u_short sa_family;          /* Address family */
  144.   char    sa_data[14];        /* Address data (maximum 14 bytes) */
  145. };
  146.  
  147. /*
  148.  * Maximum queue length for listen() calls
  149.  */
  150. #define SOMAXCONN   5
  151.  
  152. struct iovec {
  153.         caddr_t iov_base;
  154.         int     iov_len;
  155. };
  156.  
  157. /*
  158.  * Message header for sendmsg() and recvmsg() calls - this is a
  159.  * struct definition kept from 4.3 BSD to preserve compatibility
  160.  * with the Acorn TCP/IP suite.
  161.  */
  162. struct msghdr {
  163.   caddr_t      msg_name;         /* Address (optional) */
  164.   int          msg_namelen;      /* Address size */
  165.   struct iovec *msg_iov;         /* Scatter/gather array */
  166.   int          msg_iovlen;       /* Number of elements in msg_iov */
  167.   caddr_t      msg_accrights;    /* Access rights */
  168.   int          msg_accrightslen; /* Size of msg_accrights */
  169. };
  170.  
  171. /*
  172.  * Flags for data sending/receiving calls
  173.  */
  174. #define MSG_OOB         0x1      /* Process out-of-band data */
  175. #define MSG_PEEK        0x2      /* Peek at incoming message */
  176. #define MSG_DONTROUTE   0x4      /* Send without routing */
  177. #define    MSG_EOR        0x8     /* data completes record */
  178. #define    MSG_TRUNC    0x10     /* data discarded before delivery */
  179. #define    MSG_CTRUNC    0x20     /* control data lost before delivery */
  180. #define    MSG_WAITALL    0x40     /* wait for full request or error */
  181. #define    MSG_DONTWAIT    0x80     /* this message should be nonblocking */
  182. /*
  183.  * Maximum size of a scatter/gather array
  184.  */
  185. #define MSG_MAXIOVLEN 16
  186.  
  187. /*
  188.  * Option level for socket level options
  189.  */
  190. #define SOL_SOCKET    0xffff
  191.  
  192. /*
  193.  * Available socket level options
  194.  */
  195. #define SO_DEBUG      0x0001     /* Turn on debugging */
  196. #define SO_ACCEPTCONN 0x0002     /* Socket is listening for connections */
  197. #define SO_REUSEADDR  0x0004     /* Allow local reuse of this address */
  198. #define SO_KEEPALIVE  0x0008     /* Keep connections alive */
  199. #define SO_DONTROUTE  0x0010     /* Bypass routing for this socket */
  200. #define SO_BROADCAST  0x0020     /* Allow sending of broadcast messages */
  201. #define    SO_USELOOPBACK    0x0040     /* bypass hardware when possible */
  202. #define SO_LINGER     0x0080     /* Linger on close if data present */
  203. #define SO_OOBINLINE  0x0100     /* Receive OOB data inline */
  204. #define    SO_REUSEPORT  0x0200     /* allow local address & port reuse */
  205.  
  206. #define SO_SNDBUF     0x1001     /* Output buffer size */
  207. #define SO_RCVBUF     0x1002     /* Input buffer size */
  208. #define SO_SNDLOWAT   0x1003     /* send low-water mark */
  209. #define SO_RCVLOWAT   0x1004     /* receive low-water mark */
  210. #define SO_SNDTIMEO   0x1005     /* send timeout */
  211. #define SO_RCVTIMEO   0x1006     /* receive timeout */
  212. #define SO_ERROR      0x1007     /* Get and clear error (read only) */
  213. #define SO_TYPE       0x1008     /* Get socket type (read only) */
  214.  
  215. /*
  216.  * structure used for manipulating SO_LINGER option
  217.  */
  218. struct linger {
  219.   int l_onoff;                   /* Option on/off toggle */
  220.   int l_linger;                  /* Time to linger for (in seconds) */
  221. };
  222.  
  223. /*
  224.  * Create a socket
  225.  */
  226. extern int socket(int /*af*/, int /*type*/, int /*protocol*/);
  227.  
  228. /*
  229.  * Bind a name to a socket
  230.  */
  231. extern int bind(int /*s*/, struct sockaddr * /*name*/, int /*namelen*/);
  232.  
  233. /*
  234.  * Start listening for connections on a socket
  235.  */
  236. extern int listen(int /*s*/, int /*backlog*/);
  237.  
  238. /*
  239.  * Accept a connection on a socket
  240.  */
  241. extern int accept(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  242.  
  243. /*
  244.  * Make a connection on a socket
  245.  */
  246. extern int connect(int /*s*/, const struct sockaddr */*name*/, int /*namelen*/);
  247.  
  248. /*
  249.  * Routines to receive data on a socket
  250.  */
  251. extern int recv(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/);
  252. extern int recvfrom(int /*s*/, char */*msg*/, int /*len*/, int /*flags*/,
  253.                     struct sockaddr */*from*/, int */*fromlen*/);
  254. extern int recvmsg(int /*s*/, struct msghdr */*msg*/, int /*flags*/);
  255.  
  256. /*
  257.  * Routines to send data from a socket
  258.  */
  259. extern int send(int /*s*/, const char */*msg*/, int /*len*/, int /*flags*/);
  260. extern int sendto(int /*s*/, const char */*msg*/, int /*len*/, int /*flags*/,
  261.                   const struct sockaddr */*to*/, int /*tolen*/);
  262. extern int sendmsg(int /*s*/, const struct msghdr * /*msg*/, int /*flags*/);
  263.  
  264. /*
  265.  * Manipulate socket options
  266.  */
  267. extern int setsockopt(int /*s*/, int /*level*/, int /*optname*/, const char */*optval*/, int /*optlen*/);
  268. extern int getsockopt(int /*s*/, int /*level*/, int /*optname*/, char */*optval*/, int * /*optlen*/);
  269.  
  270. /*
  271.  * Find the names of a socket and its peer
  272.  */
  273. extern int getsockname(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  274. extern int getpeername(int /*s*/, struct sockaddr */*name*/, int */*namelen*/);
  275.  
  276. #endif /* socket.h */
  277.